package com.leetcode.partition6;

/**
 * @author `RKC`
 * @date 2021/10/29 15:25
 */
public class LC551学生出勤记录1 {

    public static boolean checkRecord(String s) {
        int absentCount = 0, continualLateCount = 0;
        if (s.charAt(0) == 'A') absentCount++;
        else if (s.charAt(0) == 'L') continualLateCount++;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                absentCount++;
                continualLateCount = 0;
            } else if (s.charAt(i) == 'L' && s.charAt(i - 1) == 'L') {
                if (continualLateCount == 0) continualLateCount = 1;
                continualLateCount++;
            } else if (s.charAt(i) == 'P') {
                continualLateCount = 0;
            }
            if (absentCount >= 2 || continualLateCount >= 3) return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(checkRecord("LL"));
    }
}
